package com.fast.fastenjoy.base.dao.sqltemplate.transformer;

import java.util.HashMap;
import java.util.Map;

import com.fast.fastenjoy.base.utils.StringExUtils;

/**
 * Map数据转换器
 * @author chenliaohua
 *
 */
public class MapSqlMapResultTransformer extends ResultTransformerEx{

	private static final long serialVersionUID = 4430068662713553107L;
	
	public static MapSqlMapResultTransformer INSTANCE = new MapSqlMapResultTransformer(Map.class);
	
	public static boolean isMap(String entityClass){
		
		return StringExUtils.equalsIgnoreCase(entityClass, "map");
	}
	
	public static boolean isMap(Class<?> entityClass){
		
		return entityClass != null && 
				(entityClass.equals(Map.class) || entityClass.equals(HashMap.class));
	}
	
	
	private MapSqlMapResultTransformer(Class<?> entityClass) {
		super(entityClass);
	}

	public Object transformTuple(Object[] objs, String[] colNames) {
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		for(int i = 0,len = colNames.length; i < len; i++){
			map.put(colNames[i], objs[i]);
		}
		
		return map;
	}

}
